package com.me.EpicVN.Utli;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;

import android.util.Log;

public class htmlReader {
    TagNode rootNode;
    
    public htmlReader(URL htmlPage) throws IOException
    {
        HtmlCleaner cleaner = new HtmlCleaner();
        rootNode = cleaner.clean(htmlPage);
    }

    public void  getLinksByClass(String CSSClassname)
    {
    	List<String> list = new ArrayList<String>();
    	List<String> list1 = new ArrayList<String>();
	        TagNode linkElements[] = rootNode.getElementsByName("img", true);
	        for (int i = 0; linkElements != null && i < linkElements.length; i++)
	        {        
	        	
	            String classType = linkElements[i].getAttributeByName("class");
	            Log.e(classType+"-GoHERE", "GoHERE");
	            if (classType != null && classType.contains("epic"))
	            {
	            	
	            	String str = (linkElements[i].getAttributeByName("src"));
	            	String str1 = (linkElements[i].getAttributeByName("alt"));
	            	if(str1!=null)
	            	{
		            	Log.v("HTML", "str = "+str);
		            	list.add(str);
		            	GlobalVariable.listImage = list;
	            	}
	            }
	            
	        }
	        
	        TagNode linkElements1[] = rootNode.getElementsByName("a", true);
	        for (int i = 0; linkElements1 != null && i < linkElements1.length; i++)
	        {        
	        	
	            String classType = linkElements1[i].getAttributeByName("class");
	            Log.e(classType+"-GoHERE", "GoHERE");
	            if (classType != null && classType.contains("jump_focus"))
	            {
	            	
	            	String str = (linkElements1[i].getText().toString());
		            	Log.v("HTML", "str1111 = "+str);
		            	list1.add(str);
		            	GlobalVariable.listTitle = list1;
	            }
	            
//	            String classType1 = linkElements1[i].getAttributeByName("title");
//	            if (classType1 != null && classType1.contains("Hài hước"))
//	            {
//	            	
//	            	String str = (linkElements1[i].getText().toString());
//		            	Log.v("HTML", "strNAmE = "+str);
//	            }
//	            
	            
	            
	            
	        }
        
        

    }
}
